package com.mini.model;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mini.config.EncryptField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.Date;

/**
 * Created with meng.
 * User: meng5
 * Date: 2020-02-25
 * Description:
 */
@Entity(name = "business_big_lesson_order")
@Data
@ToString
@ApiModel(value = "大课订单-小程序订单表")
@DynamicInsert(value = true)
@DynamicUpdate(value = true)
public class BusinessBigLessonOrder {

    @Id
    @ApiModelProperty(value = "订单编号-对应的是小程序同步过来的大课订单")
    private String orderNo;

    @ApiModelProperty(value = "手机号")
    @EncryptField
    private String phoneNumber;


    private Long lessonId;
//    @Excel(name="小程序大课名称", orderNum = "19")
    @ApiModelProperty(value = "大课课程名称")
    private String lessonName;

    private String teachPlanId;
    private String teachPlanName;
    private String skuCode;
    private String skuName;

//    @Excel(name = "小程序大课创建订单时间", format = "yyyy-MM-dd HH:mm:ss", orderNum = "20")
    @ApiModelProperty(value = "订单生成时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date orderCreateTime;
    @ApiModelProperty(value = "支付发起时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date payStartTime;
//    @Excel(name = "小程序大课支付完成时间", format = "yyyy-MM-dd HH:mm:ss", orderNum = "21")
    @ApiModelProperty(value = "支付完成时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date payFinishTime;
    @ApiModelProperty(value = "订单状态")
    private String orderState;
//    @Excel(name = "小程序大课订单状态", orderNum = "22")
    @ApiModelProperty(value = "订单状态name")
    private String orderStateStr;
    @ApiModelProperty(value = "商品金额")
    private Float price;

    @ApiModelProperty(value = "支付金额")
    private Float payAmount;
    private Double payAmountStage1;
    private Double payAmountStage2;

    @ApiModelProperty(value = "优惠金额")
    private Float couponAmount;
    @ApiModelProperty(value = "用户昵称")
    private String username;
    @ApiModelProperty(value = "优惠码")
    private String couponCode;

    private String orderSourceType;

    private String remark;


    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "退费时间")
    private Date refundTime;
    @ApiModelProperty(value = "退费状态")
    private String refundStatus;
    @ApiModelProperty(value = "退费金额")
    private Double refundAmount;

    @ApiModelProperty(value = "升班/转班状态code")
    private String changeClassStatus;
    @ApiModelProperty(value = "升班/转班状态Name")
    private String changeClassStatusName;
    @ApiModelProperty(value = "升班/转班状态关联订单号")
    private String changeClassRelatedKey;
    @ApiModelProperty(value = "升班/转班状态时间")
    private String changeClassTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "优惠券订单类型：0-普通订单，1-定金券，2-尾款")
    private Integer orderDepositType;

    @ApiModelProperty(value = "定金尾款绑定状态：1-绑定，0-未绑定")
    private Integer depositMergeState;

    @ApiModelProperty(value = "用来关联orderDepositType=1和2的订单的关键字段，定金相关-存优惠券码，首付款相关-存首付款码")
    private String relatedKey;
    @ApiModelProperty(value = "它直接关联的订单号")
    private String refOrderNo;
    @ApiModelProperty(value = "分期订单的分期数")
    private Integer installmentNum;
    @ApiModelProperty(value = "0-传统订单/1-BF订单")
    private Integer orderChannelType;



    public enum OrderSourceType{
        ONLINE("1"),
        OFFLINE("0");

        private String code;

        OrderSourceType(String code) {
            this.code = code;
        }

        public String getCode() {
            return code;
        }
    }

//    {
//        "0": "生成订单",
//            "5": "支付中",
//            "10": "支付失败",
//            "15": "支付完成",
//            "20": "订单超时",
//            "25": "取消订单",
//            "30": "退款发起",
//            "35": "退款中",
//            "40": "退款成功",
//            "45": "退款失败",
//    }
    public enum OrderState{
        PAYING("5", "支付中"),
        PAY_FINISH("15", "支付完成"),
        PAY_CANCEL("25", "支付取消"),
        PAY_CREATE("0", "生成订单"),
        PAY_FAIL("10", "支付失败"),
        PAY_TIMEOUT("20", "订单超时"),
        PAY_REFUND_CREATE("30", "退款发起"),
        PAY_REFUND_ING("35", "退款中"),
        PAY_REFUND_SUCCESS("40", "退款成功"),
        PAY_REFUND_FAIL("45", "退款失败")
        ;

        private String state;
        private String name;


        OrderState(String state, String name) {
            this.state = state;
            this.name = name;
        }

        public static OrderState getByState(String state){
            if(StringUtils.isBlank(state)){
                return null;
            }

            for(OrderState os : OrderState.values()){
                if(os.getState().equals(state)){
                    return os;
                }
            }

            return  null;
        }

        public String getState() {
            return state;
        }

        public String getName() {
            return name;
        }
    }


    public enum OrderDeposiType{

        ORDER_NORMAL(0, "普通订单"),
        ORDER_PDEPOSIT(1, "定金订单"),
        ORDER_BALANCE(2, "尾款订单");

        private int type;
        private String name;

        OrderDeposiType(int type, String name) {
            this.type = type;
            this.name = name;
        }

        public int getType() {
            return type;
        }

        public String getName() {
            return name;
        }
    }






















}